package cn.wd.service.impl;

import cn.wd.domain.ConfigInfo;
import cn.wd.mapper.ConfigInfoMapper;
import cn.wd.page.PageResult;
import cn.wd.qo.QueryObject;
import cn.wd.service.IConfigInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConfigInfoServiceImpl implements IConfigInfoService {

    private final ConfigInfoMapper mapper;

    public ConfigInfoServiceImpl(ConfigInfoMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public List<ConfigInfo> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public void save(ConfigInfo obj) {
        mapper.insert(obj);
    }

    @Override
    public void updateById(ConfigInfo obj) {
        mapper.updateByPrimaryKey(obj);
    }

    @Override
    public ConfigInfo selectById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
        public PageResult<ConfigInfo> query(QueryObject qo) {
            Long total = mapper.selectForCount(qo);
            if (total == 0) {
                return PageResult.empty(qo.getCurrentPage(),qo.getPageSize());
            }
            List<ConfigInfo> configInfoList = mapper.selectForList(qo);
            return new PageResult<>(qo.getCurrentPage(),qo.getPageSize(),total,configInfoList);
        }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public ConfigInfo selectByKey(String key) {
        return mapper.selectByKey(key);
    }

    @Override
    public void batchDelete(Long[] deletedIds) {
        mapper.batchDelete(deletedIds);
    }
}
